//
//  CommonStwxItemViewModel.m
//  EnvironmentalProtection
//
//  Created by HCreater on 2018/10/23.
//  Copyright © 2018年 HCreater. All rights reserved.
//

#import "CommonStwxItemViewModel.h"

#import "ArticleListData.h"

@interface CommonStwxItemViewModel ()

/// 商品模型
//@property (nonatomic, readwrite, strong) EnterpriseInfoData* epInfoData;
@property (nonatomic, readwrite, strong) id data;
@property (nonatomic, readwrite, assign) NSInteger type;

@property (nonatomic, readwrite, copy) NSString* articleID;

@property (nonatomic, readwrite, copy) NSString* content;
@property (nonatomic, readwrite, copy) NSString* name;
@property (nonatomic, readwrite, copy) NSString* goodNum;
@property (nonatomic, readwrite, copy) NSString* commentNum;
@property (nonatomic, readwrite, copy) NSString* readLastDate;
@property (nonatomic, readwrite, copy) NSString* readNum;
@property (nonatomic, readwrite, copy) NSString* imgurl;

@end

@implementation CommonStwxItemViewModel

- (instancetype)initWithData:(NSString *)data cellHeight:(CGFloat)cellHeight
{
    self = [super init];
    if (self)
    {
        //        _epInfoData = data;
        
        _data = data;
        
        /// cellHeight+2（2容错）
        _cellHeight = MHUIScaleValue(cellHeight)+2;
        
        @weakify(self);
        [[RACObserve(self, data) distinctUntilChanged] subscribeNext:^(id x)
        {
            @strongify(self);
            
            ArticleListData* aListData = x;
            
            self.articleID = aListData.articleID;
            
            self.content = aListData.title;
            self.name = aListData.from;
            self.goodNum = HCStrFormat(@"%d", (int)aListData.praiseCount);
            self.commentNum = HCStrFormat(@"%d", (int)aListData.commentCount);
            self.readNum = HCStrFormat(@"阅读量：%d", 0);
            self.readLastDate = aListData.addTime;
            self.imgurl = aListData.user.wxHeadImg;
            self.type = aListData.type;
        }];
    }
    
    return self;
}

@end
